from pathlib import Path
from PIL import Image,ImageTk
import tkinter as tk


def img_resize(SIZE,UNIT):
    cur_path = Path(__file__)
    root_path = cur_path.parent.parent
    img_root_path = root_path.joinpath(Path('pictures'))
    # print('img_root_path:',img_root_path)
    imgs = []
    for i in range(SIZE):
        img = Image.open(img_root_path.joinpath(Path('panda'+str(i)+'.jpg')))
        img = img.resize((UNIT, UNIT))
        img = ImageTk.PhotoImage(img)
        imgs.append(img)
    print(img_root_path.joinpath(Path('panda'+str(i)+'.jpg')))
    return imgs


class DynamicImage:
    def __init__(self, master, Size, file_path):
        self.master = master
        self.canvas = tk.Canvas(master, width=Size, height=Size)
        self.canvas.pack()
        self.image = Image.open(file_path)
        self.image = self.image.resize((Size, Size), Image.Resampling.LANCZOS)
        self.photo_image = ImageTk.PhotoImage(self.image)
        self.image_width = self.photo_image.width()
        self.canvas.create_image(0, 0, anchor='nw', image=self.photo_image)
        self.load_image(-Size)

    def load_image(self, i):
        self.canvas.delete('all')
        self.canvas.create_image(-i, 0, anchor='nw', image=self.photo_image)
        if i:
            self.master.after(10, self.load_image, i+2)
            self.canvas.image=self.photo_image


if __name__=='__main__':
    import tkinter as tk
    win=tk.Tk()
    img_resize(6,10)
    win.mainloop()